﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>Upload</title>
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    @if (false)
    {
        <script type="text/javascript" src="../../scripts/jquery-1.5.1-vsdoc.js"></script>    
    }
    <link href="@Url.Content("~/Scripts/uploadify-v2.1.4/uploadify.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/uploadify-v2.1.4/swfobject.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/uploadify-v2.1.4/jquery.uploadify.v2.1.4.min.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#uploadify").uploadify({
                'uploader': '@Url.Content("~/Scripts/uploadify-v2.1.4/uploadify.swf")',
                //'script': '@Url.Content("~/Scripts/uploadify-v2.1.4/uploadfile.ashx")', //后台处理
                'cancelImg': '@Url.Content("~/Scripts/uploadify-v2.1.4/cancel.png")', //单个取消按钮
                'folder': '@Url.Content("~/uploadfile")', //文件夹
                'queueID': 'fileQueue', //文件队列
                'auto': true,
                'multi': false, //多文件上传，
                'simUploadLimit': '3', //允许多文件上传的文件数
                'fileExt': '*.doc;*.m4r',
                'fileDesc': '*.doc;*.m4r',
                'buttonText': 'select',
                'buttonImg': '@Url.Content("~/Scripts/uploadify-v2.1.4/browse.png")',
                'width': '100',
                'height': '28',
                'sizeLimit': '6000000', //大小限制，6M                
                onError: function (event, queueID, fileObj) {
                    alert('error ' + d.type + ": " + d.info);
                },
                onComplete: function (event, queueID, fileObj, response, data) {
                    //alert("成功上传,平均速率："+data.speed+"kb/s");
                    if (response == "0")
                        $("#haveupfile").append("<p style='color:#f00'>上传" + fileObj.name + "失败！<a onclick='deletefile(\"\",this)'>删除</a></p>");
                    else if (response == "1")
                        $("#haveupfile").append("<p style='color:#f00'>" + fileObj.name + "文件格式错误！<a onclick='deletefile(\"\",this)'>删除</a></p>");
                    else
                        $("#haveupfile").append("<p>上传<b>" + response + "</b>成功！<a onclick='deletefile(\"" + response + "\",this)' style='cursor:pointer;'>删除</a></p>");
                },
                //                onAllComplete:function(e,d)
                //                {
                //                    //alert("成功上传"+d.filesUploaded+"个文件，错误："+d.errors);
                //                },
                onSelect: function (e, q, f) {
                    if (f.size > 5242880) {
                        alert("文件大小超过限制！请重新选择");
                        uploadifyCancel(q);
                    }

                    alert(f.name);
                }
            });
        });
        function deletefile(url, obj) {
            if (url != "") {
                $.post("/uploadJs/delfile.ashx", { "fileurl": url }, function (_result) {
                    if (_result == "1") alert("删除成功！");
                    else if (_result == "2") alert("删除异常！");
                    else if (_result == "3") alert("请求失败！");
                    else if (_result == "4") alert("不存在该文件！");
                    $(obj).parent().remove();
                });
            }
            else
                $(obj).parent().remove();
        } 
    </script>
</head>
<body>
    <div id="fileQueue">
    </div>
    <input type="file" name="uploadify" id="uploadify" />
    <p>
        <a href="javascript:$('#uploadify').uploadifyUpload()">上传</a> | <a href="javascript:$('#uploadify').uploadifyClearQueue()">
            取消上传</a>
    </p>
    <div id="haveupfile">
    </div>
</body>
</html>
